/**
 * @author LKQ
 * @date 2022/2/23 11:39
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.reverseOnlyLetters("Test1ng-Leet=code-Q!"));
    }
    public String reverseOnlyLetters(String s) {
        int n = s.length(), left = 0, right = n - 1;
        char[] chars = s.toCharArray();
        while (left < right) {
            if (!Character.isLetter(chars[left])) {
                left++;
            }else if (!Character.isLetter(chars[right])) {
                right--;
            }else {
                char temp = chars[left];
                chars[left] = chars[right];
                chars[right] = temp;
                left++;
                right--;
            }
        }
        return  new String(chars);
    }
}
